package testClasses.misc;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import testClasses.ATest;
import testClasses.TestingSystem;
import tiles.HexTileController;
import tiles.HexTileViewBuilder;
import tiles.HexTileModel;
import tiles.HexTileView;
import utilities.CoordConvert;
import utilities.HexTileGen;
import utilities.Key;
import utilities.MVCMaker;
import view.EViewList;
import view.View;

import com.jme3.app.SimpleApplication;
import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;

import controller.AbstractController;

import eventManager.EventManager;
import events.stateMachine.strategyState.DefaultViewEvent;

public class TestHexTiles extends ATest {

	public TestHexTiles(TestingSystem system) {
		super(system);
		this.name = "TestHexTiles";
	}

	private static final Logger logger = Logger.getLogger(TestHexTiles.class.getName());
	
	public static String name = "TestHexTiles";
	
	public boolean execute() {
		logger.log(Level.INFO, "TestHexTiles: execute()");
		
		HashMap<Key, AbstractController> controllerMap = new HashMap<Key, AbstractController>();
		eventManager.addControlMapReference(controllerMap);
		
		ArrayList<ArrayList<Integer>> tileLocations = HexTileGen.genTileLocations(20);
		//ArrayList<Double> cartesian;
		HexTileViewBuilder tileViewFact = new HexTileViewBuilder();	
		
		
		for (ArrayList<Integer> location: tileLocations) {
			//cartesian = CoordConvert.hex2Cart(location);
			
			
			HexTileModel m = new HexTileModel(location.get(0), location.get(1), location.get(2));		
			//Material material = new Material(assets, "Common/MatDefs/Misc/Unshaded.j3md");
					
			HashMap<EViewList, View> v = tileViewFact.buildViews(assetManager);//new FVHexTile()VHexTile(EViewList.DEFAULT, material, null);		
			HexTileController c = new HexTileController(eventManager);

			MVCMaker.linkElements(m, v, c);
			System.out.println("Controller keySet size: " + c.getEvents().keySet().size());
			eventManager.addAllListeners(c, c.getEvents().keySet());

			controllerMap.put(m.getKey(), c);			
		}
		
		//Execution
		eventManager.queueEvent(new DefaultViewEvent(node));
		eventManager.procEvents(1000);
		
		
		
		
		return true;
	}

	
	
	

}
